#include "Newton.h"

using namespace std;
int main(){
    int n=6;
    vector<double> x={0,6,10,13,17,20,28};
    vector<double> y2={6.67,16.1,18.9,15.0,10.6,9.44,8.89};
    vector<double> y1={6.67,17.3,42.7,37.3,30.1,29.3,28.7};

    Polynomial a(6);
    vector<double> a_0(7);
    vector<double> a_1(7);
    a_0=a.makepoly(x,y1);
    cout <<"Pn(x)=";
    for (int i=0;i<n;i++){
        cout << a_0[i];
        if (i>=1){
        cout <<"*(x-("<< x[0] <<"))";
        }
        for(int j=1;j<i;j++){
            cout << ".*(x-("<< x[j]<<"))";
        }
        if(a_0[i+1]<0){
        }
        else{
        cout <<"+";
        }
    }
    cout << a_0[n];
    for (int j=0;j<n;j++){
        cout << ".*(x-("<< x[j]<<"))";
    }
    cout <<endl;
    a_1=a.makepoly(x,y2);
    cout <<"Pn(x)=";
    for (int i=0;i<n;i++){
        cout << a_1[i];
        if (i>=1){
        cout <<"*(x-("<< x[0] <<"))";
        }
        for(int j=1;j<i;j++){
            cout << ".*(x-("<< x[j]<<"))";
        }
        if(a_1[i+1]<0){
        }
        else{
        cout <<"+";
        }
    }
    cout << a_1[n];
    for (int j=0;j<n;j++){
        cout << ".*(x-("<< x[j]<<"))";
    }
    cout <<endl;
    return 0;


}